package com.ruoyi.web.controller.business;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.business.domain.dto.SalesStatisticsDTO;
import com.ruoyi.business.service.IStatisticsService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;

/**
 * 数据统计控制器
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/business/statistics")
public class StatisticsController extends BaseController {
    
    @Autowired
    private IStatisticsService statisticsService;
    
    /**
     * 获取销售统计数据
     */
    @PreAuthorize("@ss.hasPermi('business:statistics:list')")
    @GetMapping("/sales")
    public AjaxResult getSalesStatistics() {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        Long userId = loginUser.getUserId();
        SalesStatisticsDTO statistics = statisticsService.getSalesStatistics(userId);
        return AjaxResult.success(statistics);
    }
    
    /**
     * 获取概览数据（包含销售统计）
     */
    @PreAuthorize("@ss.hasPermi('business:statistics:list')")
    @GetMapping("/overview")
    public AjaxResult getOverview() {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        Long userId = loginUser.getUserId();
        SalesStatisticsDTO statistics = statisticsService.getSalesStatistics(userId);
        return AjaxResult.success(statistics);
    }
} 